// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';


// import VueAxios from 'vue-axios' // 报错的话则npm安装依赖
import axios from 'axios'
Vue.prototype.$http=axios;
//指定baseURL
axios.defaults.baseURL = '/api';
//请求超时的时间
axios.defaults.timeout=1000,
//默认的contenttype为json以及utf-8；
axios.defaults.headers={'Content-Type': 'application/json;charset=UTF-8'}

Vue.use(ElementUI);

router.beforeEach(function(to, from, next) {

  if (to.meta.needLogin) {
    //页面是否登录
    if (sessionStorage.getItem("LoginName")) {
      //本地存储中是否有token(uid)数据
      next(); //表示已经登录
    } else {
      //next可以传递一个路由对象作为参数 表示需要跳转到的页面
      next({
        path: '/login',
        query: {redirect: to.fullPath}
        // name:'login'
      });
    }
  } else {
    //表示不需要登录
    next(); //继续往后走
  }
});


Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
